package cn.foolishbird.crow.spring.security.token;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * @author foolish bird
 **/
public class JWTAuthenticationToken<T> extends AbstractAuthenticationToken {

    private static final long serialVersionUID = 334104757391431615L;

    /**
     * jwtString
     */
    private String jwtToken;

    /**
     * jwt 解析后的对象
     */
    private T jwt;

    public JWTAuthenticationToken() {
        super(null);
    }


    /**
     * Creates a token with the supplied array of authorities.
     *
     * @param authorities the collection of <tt>GrantedAuthority</tt>s for the principal
     *                    represented by this authentication object.
     */
    public JWTAuthenticationToken(Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
    }


    public JWTAuthenticationToken(String jwtToken, T jwt) {
        super(null);
        this.jwtToken = jwtToken;
        this.jwt = jwt;
    }

    @Override
    public Object getPrincipal() {
        return this.jwtToken;
    }

    @Override
    public Object getCredentials() {
        return this.jwtToken;
    }

    /**
     * 获取jwtToken 的 唯一业务码
     *
     * @return
     */
    public String jti() {
        return this.jwtToken;
    }

    public String getJwtToken() {
        return jwtToken;
    }

    public void setJwtToken(String jwtToken) {
        this.jwtToken = jwtToken;
    }

    public T getJwt() {
        return jwt;
    }

    public void setJwt(T jwt) {
        this.jwt = jwt;
    }

}
